package com.business.service.taskBat.impl;

import com.business.model.taskBat.TaobaoImportMsg;
import com.business.mapper.taskBat.TaobaoImportMsgMapper;
import com.business.service.taskBat.TaobaoImportMsgService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author maotao.li
 * @since 2017-12-08
 */
@Service
public class TaobaoImportMsgServiceImpl extends ServiceImpl<TaobaoImportMsgMapper, TaobaoImportMsg> implements TaobaoImportMsgService {

	@Override
	public TaobaoImportMsg checkAndJudge(TaobaoImportMsg taobaoImportMsg) {
		List<TaobaoImportMsg> list = this.baseMapper.checkAndJudge(taobaoImportMsg);
		String notes = ",";
		for(TaobaoImportMsg t : list) {
			if(taobaoImportMsg.getId()!=null && t.getId().longValue()==taobaoImportMsg.getId().longValue()){
				continue;//添加 和 修改的相同数据则跳过
			}
			if(null != t.getTheCode() && !"".equals(t.getTheCode())&&t.getTheCode().equals(taobaoImportMsg.getTheCode())){
				if(!notes.contains(",编号重复")){
					notes +=",编号重复";
				}
			}
			if(null != t.getWxOpenid() && !"".equals(t.getWxOpenid())&&t.getWxOpenid().equals(taobaoImportMsg.getWxOpenid())) {
				if(!notes.contains(",微信OPENID重复")){
					notes +=",微信OPENID重复";
				}
			}
			if(null != t.getIpAddr() && !"".equals(t.getIpAddr())&&t.getIpAddr().equals(taobaoImportMsg.getIpAddr())) {
				if(!notes.contains(",IP重复")){
					notes +=",IP重复";
				}
			}
			if(null != t.getWeixinCode() && !"".equals(t.getWeixinCode()) && t.getWeixinCode().equals(taobaoImportMsg.getWeixinCode())){
				if(!notes.contains(",微信号重复")){
					notes +=",微信号重复";
				}
			}
			if(null != t.getAccounts() && !"".equals(t.getAccounts()) && t.getAccounts().equals(taobaoImportMsg.getAccounts())){
				if(!notes.contains(",旺旺号重复")){
					notes += ",旺旺号重复";
				}
			}
			if(null != t.getPhoneNum() && !"".equals(t.getPhoneNum()) && t.getPhoneNum().equals(taobaoImportMsg.getPhoneNum())){
				if(!notes.contains(",手机号重复")){
					notes += ",手机号重复";
				}
			}
		}
		notes = notes.equals(",")?"" : notes.replace(",,", "");
		if(!"".equals(notes)) {
			taobaoImportMsg.setBlackWhite(1);//黑白名单  0 正常 1 黑名单
			
		}else{
			taobaoImportMsg.setBlackWhite(0);//黑白名单  0 正常 1 黑名单
		}
		taobaoImportMsg.setNotes(notes);
		taobaoImportMsg.setCheckJudge(1);//是否验证数据 0未验证  1已验证
		return taobaoImportMsg;
	}

	@Override
	public void importMsgDBCall(TaobaoImportMsg taobaoImportMsg) {
		this.baseMapper.importMsgDBCall(taobaoImportMsg);
	}
	
}
